import { Cache } from "../../cache/Cache";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "../common/BaseItem";
import { ItemConfig } from "../../resource/ItemConfig";
import { EBind } from "../../../../Message/Public/EBind";
import { ItemData } from "../../resource/info/ItemData";
import { ShopConfig } from "../../resource/ShopConfig";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { _shopItem } from "../../../../this/_shopItem";
type int = number;
//class WuXingQualityBuyPanel
    
    export  class WuXingQualityBuyPanel /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int, arg3: Boolean=true, arg4: Boolean=true, arg5: Boolean=true, arg6: int=1703)
        {
            
            this._cate = arg1;
            this._type = arg2;
            this._autoBuyShow = arg4;
            this._coinShow = arg5;
            this._showTitle = arg3;
            this._shopRule = arg6;
            this.initUI();
            return;
        }

        public get moneyNeed(): int
        {
            return -this._moneyNeed;
        }

        public updateNeecMoney(arg1: int): void
        {
            if (this._moneyCostTxt) 
            {
                this._moneyCostTxt.textField.text = arg1.toString();
                this._moneyNeed = Cache.instance.role.money.coin + Cache.instance.role.money.coinBind - arg1;
                if (this._moneyNeed > 0) 
                {
                    this._moneyCostTxt.textField.textColor = 65280;
                }
                else 
                {
                    this._moneyCostTxt.textField.textColor = 16711680;
                }
            }
            return;
        }

        public get autoBuyCheck(): Boolean
        {
            if (this._autoBuyCheck) 
            {
                return this._autoBuyCheck.selected;
            }
            return false;
        }

        public clear(): void
        {
            this._item = null;
            if (this._moneyCostTxt) 
            {
                this._moneyCostTxt.textField.text = "0";
                this._moneyCostTxt.textField.textColor = 65280;
            }
            this._itemName.htmlText = this._itemData.itemInfo.htmlName + HTMLUtil.addColor("*0", this._itemData.itemInfo.colorStr);
            return;
        }

        public get yuanbaoPrice(): int
        {
            if (this._shopItem) 
            {
                if (this._shopItem.tshopSell.offer > 0) 
                {
                    return this._shopItem.tshopSell.offer;
                }
                return this._shopItem.tshopSell.price;
            }
            return 0;
        }

        public get amount(): int
        {
            return this._baseItem.amount;
        }

        public buyItem(arg1: int, arg2: Boolean=false): void
        {
            var loc1=null;
            if (arg2) 
            {
                loc1 = QuickBuyWindow.instance;
                loc1.update(this._shopItem);
                loc1.updateDefaultAmount(arg1);
                loc1.show();
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, {"shopItemInfo": _shopItem, "amount": arg1}));
            }
            return;
        }

        protected initUI(): void
        {
            var loc2=null;
            var loc3=null;
            if (this._showTitle) 
            {
                this._titleTxt = ObjCreate.createTextField(Language.getString(26319) + "：", 0, 0, 100, 20, this);
                this._titleTxt.textColor = GlobalStyle.color1Uint;
                this._bg = ResouceConst.getScaleBitmap(ImagesConst.DisabledBg);
                this._bg.x = -10;
                this._bg.y = -5;
                addChild(this._bg);
                this._bg.setSize(284, 70);
            }
            if (this._autoBuyShow) 
            {
                this._autoBuyCheck = ObjCreate.createCheckBox(Language.getString(26320), 175, -7, 110, 28, this);
                this._autoBuyCheck.textField.filters = [FilterConst.nameGlowFilter];
            }
            this._itemBg = GlobalClass.getBitmap(ImagesConst.PackItemBg);
            this._itemBg.x = 0;
            this._itemBg.y = 20;
            addChild(this._itemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.x = this._itemBg.x + 3;
            this._baseItem.y = this._itemBg.y + 3;
            addChild(this._baseItem);
            var loc1=ItemConfig.instance.getItemByType(this._cate, this._type, EBind._EBindNo).item.code;
            this._itemData = new ItemData(loc1);
            this._baseItem.itemData = this._itemData;
            this._baseItem.toolTipData = this._itemData.getToolTipData();
            this._shopItem = ShopConfig.instance.getGoldItemByType(this._cate, this._type, -1, EPrictUnit._EPriceUnitGold, this._shopRule);
            this._itemName = ObjCreate.createTextField("", this._itemBg.x + this._itemBg.width + 2, this._itemBg.y, 120, 20, this);
            this._itemPriceTxt = ObjCreate.createTextField("", this._itemName.x, this._itemName.y + 22, 20, 20, this);
            this._itemPriceTxt.textColor = 16776960;
            if (this._shopItem.tshopSell.offer > 0) 
            {
                this._itemPriceTxt.text = this._shopItem.tshopSell.offer.toString();
            }
            else 
            {
                this._itemPriceTxt.text = this._shopItem.tshopSell.price.toString();
            }
            this._itemPriceBmp = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this._itemPriceBmp.x = this._itemPriceTxt.x + 20;
            this._itemPriceBmp.y = this._itemPriceTxt.y;
            addChild(this._itemPriceBmp);
            this._numStep = ObjCreate.createGNumericStepper(this._itemPriceBmp.x + this._itemPriceBmp.width + 4, this._itemPriceBmp.y - 3, 50, 20, this);
            this._buyBtn = ObjCreate.createGButton(Language.getString(26321), this._numStep.x + this._numStep.width + 2, this._numStep.y, 40, 20, this, "Button");
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickHandler);
            if (this._coinShow) 
            {
                loc2 = GlobalClass.getScaleBitmap(ImagesConst.DisabledBg, new Object /* flash.geom.Rectangle */(4, 4, 36, 21));
                loc2.x = this._autoBuyCheck.x + 15;
                loc2.y = this._buyBtn.y + 2;
                loc2.width = 75;
                loc2.height = 18;
                addChild(loc2);
                loc3 = GlobalClass.getBitmap(ImagesConst.Tongqian_bind_small);
                loc3.x = loc2.x + loc2.width - loc3.width;
                loc3.y = loc2.y;
                addChild(loc3);
                this._moneyCostTxt = ObjCreate.createLabel("0", loc2.x + 2, loc2.y, 50, 20, flash.text.TextFormatAlign.LEFT, this, false, 15859633);
            }
            this.updatePackData();
            return;
        }

        protected onBuyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.buyItem(this._numStep.value);
            return;
        }

        public updateData(arg1: ItemData): void
        {
            this._item = arg1;
            return;
        }

        public updateNeedCount(arg1: int): void
        {
            this._itemName.htmlText = this._itemData.itemInfo.htmlName + HTMLUtil.addColor("*" + arg1, this._itemData.itemInfo.colorStr);
            return;
        }

        public updatePackData(): void
        {
            var loc1=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(this._cate, this._type);
            this._baseItem.amount = loc1;
            if (loc1 != 0) 
            {
                this._baseItem.filters = null;
            }
            else 
            {
                this._baseItem.filters = [FilterConst.colorFilter];
            }
            return;
        }

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_titleTxt: Object /* flash.text.TextField */;

        protected /* var */_autoBuyCheck: GCheckBox;

        protected /* var */_okBuyCheck: GCheckBox;

        protected /* var */_itemBg: Object /* flash.display.Bitmap */;

        protected /* var */_baseItem: BaseItem;

        protected /* var */_itemData: ItemData;

        protected /* var */_shopItem: ShopItemInfo;

        protected /* var */_itemName: Object /* flash.text.TextField */;

        protected /* var */_itemPriceTxt: Object /* flash.text.TextField */;

        protected /* var */_itemPriceBmp: Object /* flash.display.Bitmap */;

        protected /* var */_numStep: GNumericStepper;

        protected /* var */_buyBtn: GButton;

        protected /* var */_moneyCostTxt: GLabel;

        protected /* var */_item: ItemData;

        protected /* var */_cate: int;

        /* internal */ /* var */_moneyNeed: int;

        protected /* var */_shopRule: int;

        protected /* var */_autoBuyShow: Boolean;

        protected /* var */_coinShow: Boolean;

        protected /* var */_showTitle: Boolean;

        protected /* var */_type: int;
    }
